//
//  CoreTextController.m
//  TangQiao
//
//  Created by 宜必鑫科技 on 2017/10/11.
//  Copyright © 2017年 宜必鑫科技. All rights reserved.
//

#import "CoreTextController.h"
#import "CTDisplayView.h"
#import "CTFrameParserConfig.h"
#import "CTFrameParser.h"


@interface CoreTextController ()

@property (nonatomic, strong) CTDisplayView *ctView;
@property (nonatomic, strong) CTDisplayView *ctView1;
@end

@implementation CoreTextController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 需要给每一段字体制定颜色和大小  以及其他属性
    _ctView =  [[CTDisplayView alloc]initWithFrame:CGRectMake(0, 100, WIDTH, HEIGHT - 100)];
    [self.view addSubview:_ctView];
 
    CTFrameParserConfig *config = [[CTFrameParserConfig alloc]init];
    config.width = self.ctView.width;
    config.textColor = [UIColor blueColor];
    
    NSString *str = @"假设我们采用的是直接调用drawRect的机制，先考虑这样一个问题 ,，现在有两个UIViewController A和B,A为当前view的viewController，如果此时在A中调用［B.view drawRect]";
    NSDictionary *attr = [CTFrameParser attributesWithConfig:config];
    NSMutableAttributedString *sttbuteString = [[NSMutableAttributedString alloc]initWithString:str attributes:attr];
    [sttbuteString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 7)];
        
    CoreTextData *data = [CTFrameParser parseAttributedContent:sttbuteString config:config];
    self.ctView.data = data;
    self.ctView.height = data.height;
    self.ctView.backgroundColor = [UIColor yellowColor];
    
    
    UIImageView *image  = [[UIImageView alloc]initWithFrame:CGRectMake(0, 300, WIDTH, 100)];
    image.backgroundColor = [UIColor lightGrayColor];
    UIImage *imaged = [UIImage imageNamed:[NSHomeDirectory()  stringByAppendingString:@"/Documents/image-1.jpg"]];
    image.image = imaged;
    [self.view addSubview:image];
    
    debugLog(@"%@",NSHomeDirectory());
}

@end
